package com;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @author clj
 * @date 2023/10/11
 * @desc
 */
public class CljTestAdmin {

    public static void main(String[] args) {
        getVideoLink();
    }

    static void getVideoLink() {

//        String originVideoLink = "0.74 复制打开抖音，看看【无锡旅拍的作品】麦当劳 69.9的套餐来啦，视频左下角赶紧冲！# ... https://v.douyin.com/idkMvSGQ/ a@a.aa KJV:/ 06/06";
        String originVideoLink = "3.82 11/26 BtR:/ O@x.SL  # 生活vlog日常记录 # 江南水乡美如画 小朋友15分钟跑完了这个院子\uD83D\uDE02  https://v.douyin.com/idkqQGLH/ 复制此链接，打开Dou音搜索，直接观看视频！";

        String videoLink = originVideoLink.substring(originVideoLink.lastIndexOf("http"), originVideoLink.lastIndexOf("/") + 1);

        System.out.println("1 : " + videoLink);

        //以下逻辑处理复制出来的抖音链接缺少最后一个斜杠的情况
        if ("https://v.douyin.com/".equals(videoLink)) {
            videoLink = originVideoLink.substring(originVideoLink.lastIndexOf("http"));

            System.out.println("2 : " + videoLink);

            if (!"/".equals(videoLink.substring(videoLink.length() - 1))) {
                videoLink = videoLink + "/";
                System.out.println("3 : " + videoLink);
            }

        }

        if (StringUtils.isNotEmpty(videoLink)) {
            List<String> links = Arrays.asList(videoLink.split(" "));
            if (links.size() == 1) {
                videoLink = links.get(0);
                System.out.println("4 : " + videoLink);
            }else {
                //从links列表中获取到包含http的字符串
                for (String link : links) {
                    if (link.contains("http")) {
                        videoLink = link;
                        System.out.println("5 : " + videoLink);
                    }
                }
            }
        }
    }
}
